﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace BaseFunction
{
    /// <summary>
    ///  2015-05-06 
    /// 陈钢创建
    /// MD5加密
    /// </summary>
    public class MD5Helper
    {
        public static string GetMD5String(string oldStr)
        {
            string pwd = "GRZX" + oldStr;
            byte[] asciiByte = Encoding.UTF8.GetBytes(pwd);
            byte[] md5Byte = new MD5CryptoServiceProvider().ComputeHash(asciiByte);
            string md5Pwd = Convert.ToBase64String(md5Byte);
            return md5Pwd;
        }
        /// <summary>
        /// Md5 16/32位小写加密 GUO
        /// </summary>
        /// <param name="str">要加密的字符串</param>
        /// <param name="code">16/32位</param>
        /// <returns></returns>
        public static string GetMD5String(string str, int code)
        {
            if (code == 16) //16位MD5加密（取32位加密的9~25字符） 
            {
                return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
            }
            else//32位加密 
            {
                return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
            }
        } 
    }
}
